package com.ctgu.computer.controller.topic;

import com.ctgu.computer.common.FailedMessage;
import com.ctgu.computer.common.SuccessMessage;
import com.ctgu.computer.domain.dto.CallCommentDTO;
import com.ctgu.computer.domain.dto.CommentDTO;
import com.ctgu.computer.domain.dto.FirstPageCommentDTO;
import com.ctgu.computer.domain.dto.SecondCommentDTO;
import com.ctgu.computer.domain.po.TextInfo;
import com.ctgu.computer.domain.result.PageResult;
import com.ctgu.computer.domain.result.Result;
import com.ctgu.computer.domain.vo.ImagePaths;
import com.ctgu.computer.service.CommentService;
import com.github.pagehelper.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.tika.utils.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/sys/message")
@RequiredArgsConstructor
@Tag(name = "评论相关接口")
public class CommentController {

    private final CommentService commentService;

    @Operation(summary = "评论相关的文章")
    @PostMapping("/send")
    public Result sendComment(@RequestBody CommentDTO commentDTO){
        if(StringUtils.isBlank(commentDTO.getCommentContent())||StringUtils.isEmpty(commentDTO.getCommentContent())){
            return Result.error(FailedMessage.COMMENT_NOT_NULL);
        }
        commentService.sendComment(commentDTO);
        return Result.success(SuccessMessage.COMMENT_SUCCESS);
    }

    @Operation(summary = "查看对应帖子的评论")
    @PostMapping("/look")
    public Result<PageResult> getCommentByTextId(@RequestBody FirstPageCommentDTO firstPageCommentDTO){
        if(firstPageCommentDTO.getTextId()==null){
            return Result.error();
        }
        PageResult result = commentService.pageFirstComment(firstPageCommentDTO);
        return Result.success(result);
    }

    @Operation(summary = "查看二级评论")
    @PostMapping("/inner/look")
    public Result<PageResult> getSecondComment(@RequestBody SecondCommentDTO secondCommentDTO){
        if(secondCommentDTO.getCommentId()==null){
            return Result.error();
        }
        PageResult result = commentService.pageSecondComment(secondCommentDTO);
        return Result.success(result);
    }

    @Operation(summary = "回复评论")
    @PostMapping("/call")
    public Result callComment(@RequestBody CallCommentDTO callCommentDTO){
        if(StringUtils.isBlank(callCommentDTO.getCommentContent())
                ||StringUtils.isEmpty(callCommentDTO.getCommentContent())){
            return Result.error(FailedMessage.COMMENT_NOT_NULL);
        }
        commentService.callComment(callCommentDTO);
        return Result.success(SuccessMessage.COMMENT_SUCCESS,null);
    }

    @Operation(summary = "删除评论")
    @GetMapping("/delete/{commentId}")
    public Result deleteComment(@PathVariable Integer commentId){
        commentService.delete(commentId);
        return Result.success(SuccessMessage.DELETE_SUCCESS);
    }

    @Operation(summary = "点赞评论")
    @GetMapping("/good/{commentId}")
    public Result goodComment(@PathVariable Integer commentId){
        commentService.good(commentId);
        return Result.success();
    }


}
